<template>
  <div class="home">
    <img alt="Vue logo" src="../assets/logo.png">
    <HelloWorld msg="Welcome to Your Vue.js App"/>
  </div>
</template>

<script>
// @ is an alias to /src
import HelloWorld from "@/components/HelloWorld.vue";
import axios from "axios";

// let axios.cr

export default {
  name: "home",
  components: {
    HelloWorld
  },
  beforeCreate:function(){
    axios
      .create({
          headers:{'Authorization':"Bearer " +sessionStorage.getItem("access_token")}
      })
      .get("api/Authenticate/test", {   
      })
      .then(res => {
        console.log(res);
      })
      .catch(err => {
        // console.log(err)
        console.log(err.response.status);
        if (err.response.status === 401) {
          console.log("进入401");
          this.$router.push({ name: "login" });
        }
        if(err.response.status===500){
          this.$router.push({ name: "login" });
        }
      });
  }
  // created: function() {  
  //   axios
  //     .create({
  //         headers:{'Authorization':"Bearer " +sessionStorage.getItem("access_token")}
  //     })
  //     .get("api/Authenticate/test", {   
  //     })
  //     .then(res => {
  //       console.log(res);
  //     })
  //     .catch(err => {
  //       // console.log(err)
  //       console.log(err.response.status);
  //       if (err.response.status === 401) {
  //         console.log("进入401");
  //         this.$router.push({ name: "login" });
  //       }
  //       if(err.response.status===500){
  //         this.$router.push({ name: "login" });
  //       }
  //     });
  //   // this.$message({
  //   //       message: '恭喜你，成功进入首页',
  //   //       type: 'success'
  //   //     });
  // }
};
</script>
